package com.tw.wechart2.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.tw.wechart2.R;
import com.tw.wechart2.bean.Comment;
import com.tw.wechart2.util.GlideUtil;

import java.util.List;

/**
 * @Description: tweet 评论展示adapter
 * @Author: lanteng 2020/9/16
 * @Version: 1.0
 */
public class CommonAdapter extends RecyclerView.Adapter<CommonAdapter.CommonViewHolder>  {

    private Context context;
    private List<Comment> listCommon;

    public CommonAdapter(Context context, List<Comment> listCommon) {
        this.context = context;
        this.listCommon = listCommon;
    }

    @NonNull
    @Override
    public CommonAdapter.CommonViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_comments, parent, false);
        return new CommonViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull CommonAdapter.CommonViewHolder holder, int position) {
        Comment comment = listCommon.get(position);
        GlideUtil.instance().displayImgage(context, comment.getSenderAvatar(), holder.iv_head);
        holder.tv_user_name.setText(comment.getSenderNick() + ":");
        holder.tv_common.setText(comment.getContent());
    }

    @Override
    public int getItemCount() {
        return (null == listCommon ? 0 : listCommon.size());
    }

    /**
     * @Description: 评论展示适配器
     * @Author: lanteng 2020/9/21
     * @return
     */
    class CommonViewHolder extends RecyclerView.ViewHolder {
        private ImageView iv_head;
        private TextView tv_user_name;
        private TextView tv_common;

        public CommonViewHolder(View itemView) {
            super(itemView);
            iv_head = itemView.findViewById(R.id.iv_head);
            tv_user_name = itemView.findViewById(R.id.tv_user_name);
            tv_common = itemView.findViewById(R.id.tv_common);
        }
    }

}
